package cn.rxls.community.service.impl;

import cn.rxls.community.entity.ContractConfirm;
import cn.rxls.community.enums.ContractConfirmEnum;
import cn.rxls.community.enums.ResultEnum;
import cn.rxls.community.exception.BusinessException;
import cn.rxls.community.mapper.ContractConfirmMapper;
import cn.rxls.community.result.Result;
import cn.rxls.community.service.ContractConfirmService;
import cn.rxls.community.vo.contractConfirm.ContractConfirmVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 合同确认内容(ContractConfirm)表服务实现类
 */
@Service("contractConfirmService")
@Transactional
public class ContractConfirmServiceImpl extends ServiceImpl<ContractConfirmMapper, ContractConfirm> implements ContractConfirmService {

    private final ContractConfirmMapper contractConfirmMapper;

    ContractConfirmServiceImpl(ContractConfirmMapper contractConfirmMapper) {
        this.contractConfirmMapper = contractConfirmMapper;
    }

    /**
     * 根据类型查询所有数据
     *
     * @param category 类型
     * @return 所有数据
     */
    @Override
    public List<ContractConfirmVO> selectAllByCategory(String category) {
        Integer codeByMsg = ContractConfirmEnum.getCodeByMsg(category);
        Optional.ofNullable(codeByMsg).orElseThrow(() -> new BusinessException(ResultEnum.ERROR_CONTRACTUAL_CONFIRM_TYPE));
        return contractConfirmMapper.selectAllByCategory(codeByMsg);

    }
}

